 #####          ######
#     #         #     #    ##     #####   #####  ######  #####   #    #   ####
#               #     #   #  #      #       #    #       #    #  ##   #  #
#               ######   #    #     #       #    #####   #    #  # #  #   ####
#               #        ######     #       #    #       #####   #  # #       #
#     #         #        #    #     #       #    #       #   #   #   ##  #    #
 #####          #        #    #     #       #    ######  #    #  #    #   ####


UNIT_TEST_DIR = unittest
SIMPLE_PATTERN_PATH = .

CC = gcc


CFLAGS = -Wall -I../src -I../include
CFLAGS_GCOV = -fprofile-arcs -ftest-coverage -O0
RELEASE_CFLAGS = -O2

SIMPLE_PATTERN_LIB = SimplePatternOps
LIB_SIMPLE_OPS = -L ../$(SIMPLE_PATTERN_PATH)/lib -l$(SIMPLE_PATTERN_LIB) 

SRC_DIR = src
LIB_DIR = lib



sonar: coverage

coverage:  lib_with_coverage build_check_app
	@echo "Running Coverage test"
	cd src; ../$(UNIT_TEST_DIR)/checkAll
	cd src; make extract_coverage_data

lib_with_coverage: get_version_number   
	cd src; make lib CFLAGS="$(CFLAGS)" \
                                           CFLAGS_GCOV="$(CFLAGS_GCOV)"\
                                           APPLICATION_VERSION=$(APPLICATION_VERSION)
                                           
                                           
build_check_app: 
	cd $(UNIT_TEST_DIR); make build_check_app  CFLAGS="$(CFLAGS)" CFLAGS_GCOV="$(CFLAGS_GCOV)" LIB_SIMPLE_OPS="$(LIB_SIMPLE_OPS)"

get_version_number: app_version_number.txt
	$(eval APPLICATION_VERSION := $(shell head -1 app_version_number.txt))

release: clean get_version_number 
	cd src; make lib CFLAGS="$(CFLAGS)" CFLAGS_GCOV="$(RELEASE_CFLAGS)" APPLICATION_VERSION=$(APPLICATION_VERSION) LIB_SIMPLE_OPS="$(LIB_SIMPLE_OPS)"
 


extract_coverage_data: 
	cd  src; make extract_coverage_data

clean:
	cd src; make clean
	-rm test-reports/*.log
	cd $(UNIT_TEST_DIR); make clean
